<template>
  <div class="app-container">

    <el-form :model="queryParams.domain" ref="queryForm" v-show="showSearch" :inline="true" @submit.native.prevent>
      <el-form-item label="用户名称" prop="loginUserName">
        <el-input v-model="queryParams.domain.loginUserName" placeholder="请输入角色名称" clearable size="small" style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>

      <div class="sg-btnGrounp">
        <el-button size="mini" type="info" @click="handleDelete()">剔除</el-button>
      </div>
    </el-form>



    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column label="用户名称" prop="loginUserName" :show-overflow-tooltip="true" width="200" />
      <el-table-column label="用户部门" prop="orgName" :show-overflow-tooltip="true" width="200" />
      <el-table-column label="登录时间" prop="loginTime" :show-overflow-tooltip="true" width="200" />
      <el-table-column label="登录IP" prop="loginIp1" :show-overflow-tooltip="true" width="200" />
      <el-table-column label="登录设备信息" prop="loginDevice" :show-overflow-tooltip="true" width="300" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDetail(scope.row)" >详情</el-button>
        </template>
      </el-table-column>
    </el-table>


    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />


    <el-dialog title="详情" :visible.sync="deatal.open" width="1000px" append-to-body>
      <el-table v-loading="deatal.loading" :data="deatal.dataList">
        <el-table-column label="用户名称" prop="loginUserName" :show-overflow-tooltip="true" width="100" />
        <el-table-column label="登录/退出" prop="loginFlagName" :show-overflow-tooltip="true" width="50" />
        <el-table-column label="是否成功" prop="loginSuccessFlagName" :show-overflow-tooltip="true" width="50" />
        <el-table-column label="登录时间" prop="loginTime" :show-overflow-tooltip="true" width="200" />
        <el-table-column label="登录IP" prop="loginIp1" :show-overflow-tooltip="true" width="100" />
        <el-table-column label="登录设备信息" prop="loginDevice" :show-overflow-tooltip="true" width="100" />
        <el-table-column label="备注" prop="errRemark" :show-overflow-tooltip="true" width="300" />
       </el-table>

     <pagination v-show="deatal.total>0" :total="deatal.total" :page.sync="deatal.queryParam.pageNum" :limit.sync="deatal.queryParam.pageSize"
        @pagination="getDetail" />
    </el-dialog>
  </div>
</template>

<script>
  import {
   listData,kickUsers,listDetail
  } from "@/api/system/onlineUser";

  export default {
    name: "Role",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 角色表格数据
        dataList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          domain: { },
          pageNum: 1,
          pageSize: 10,
          sortName: "",
          sortOrder: ""
        },

        deatal:{
          queryParam:{
          pageNum: 1,
          pageSize: 10,
          sortName: "",
          sortOrder: "",
          domain:{}
          },
          dataList:[],
          total:0,
          loading:true,
          open:false
        }

      };
    },
    created() {
      this.getList();

    },
    methods: {

      handleDetail(row){
          this.deatal.queryParam.domain = {userId:row.userId};
          this.deatal.open = true;
          this.getDetail();
      },
      getDetail(){
        this.deatal.loading =true;
        listDetail(this.deatal.queryParam).then(
          response => {
            this.deatal.dataList = response.data.records;
            this.deatal.total = response.data.total;
            this.deatal.loading=false;
          }
        );
      },


      /** 查询角色列表 */
      getList() {
        this.loading = true;
        listData(this.queryParams).then(
          response => {
            this.dataList = response.data.records;
            this.total = response.data.total;
            this.loading = false;
          }
        );
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.userId)
        this.single = selection.length != 1
        this.multiple = !selection.length
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      cancelMenuScope() {
        this.openRolwScope = false;
        this.reset();
      },

      // 表单重置
      reset() {
        this.resetForm("queryParams");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },




      /** 删除按钮操作 */
      handleDelete(row) {
        const roleIds = this.ids;
        if(roleIds.length == 0){
            this.msgError("请选择一条数据");
            return;
        }
        this.$confirm('是否确认剔除这些用户?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return kickUsers(roleIds);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("剔除成功");
        })
      },



    }
  };
</script>
